package com.zcc.makingfriend.service.impl;

import com.zcc.makingfriend.dao.Report;
import com.zcc.makingfriend.mapper.ArticleMapper;
import com.zcc.makingfriend.mapper.ReportMapper;
import com.zcc.makingfriend.service.ArticleService;
import com.zcc.makingfriend.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zcc
 */
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    ReportMapper reportMapper;

    @Autowired
    ArticleMapper articleMapper;

    @Override
    public int addReport(Report report) {
        int article = articleMapper.reportArticle(report.getArticleId());
        if (article == 1) {
            int r = reportMapper.addReport(report);
            if (r == 1) {
                return 1;
            }
        }
       return 0;
    }

    @Override
    public Report findReportByArticleId(Long articleId) {
        return reportMapper.findReportByArticleId(articleId);
    }

    @Override
    public Long countUnRead() {
        return reportMapper.countUnRead();
    }

    @Override
    public int readByArticleId(Long articleId) {
        return reportMapper.readByArticleId(articleId);
    }
}
